package cn.stronglink.assetmanage.business.inspection.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.entity.Asset;
import cn.stronglink.assetmanage.entity.PatrolDetail;
import cn.stronglink.assetmanage.index.view.onRecyclerListener;
import cn.stronglink.assetmanage.utils.Constants;

/**
 * 巡检详情adapter
 * Created by zhengjinglan on 2018/6/18.
 */

public class PatrolDetailAdapter extends RecyclerView.Adapter<PatrolDetailAdapter.ViewHolder> {
   private Context mContext;
    private List<Asset> datas;
    private onRecyclerListener listener;

    public PatrolDetailAdapter(Context context){
        this.mContext=context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_repair_datail,parent,false);
        return new ViewHolder(view,listener);
    }

    @Override
    public void onBindViewHolder(PatrolDetailAdapter.ViewHolder holder, int position) {
         Asset  patrolDetail=datas.get(position);
            holder.bindRepo(patrolDetail,position);
    }

    @Override
    public int getItemCount() {
        return datas==null?0:datas.size();
    }
    public void setOnItemClickListener(onRecyclerListener listener){
        this.listener=listener;
    }
    public void notifyDatasChanged(List<Asset> data){
        this.datas =  data;
        notifyDataSetChanged();
    }
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    private List<Asset> data;
    private TextView tv_check_asset_name,tv_repair_rfid_no,tv_status;
    private onRecyclerListener listener;
    private LinearLayout linearLayout;
    public ViewHolder(View itemView,onRecyclerListener listener) {
        super(itemView);
        this.listener=listener;
        tv_check_asset_name=itemView.findViewById(R.id.tv_check_asset_name);
        //Sn号
        tv_repair_rfid_no=itemView.findViewById(R.id.tv_repair_rfid_no);
        linearLayout = (LinearLayout)itemView.findViewById(R.id.ll_repair_detail);
        linearLayout.setOnClickListener(this);
        tv_status=itemView.findViewById(R.id.tv_status);
    }
    public void bindRepo(Asset repo, int position) {
        tv_check_asset_name.setText(repo.getAssetName());
        tv_repair_rfid_no.setText(repo.getSerialNo());
        int bindStatus = repo.getStatus();
        if (bindStatus == Constants.STATUS_THREE) {
            tv_status.setText(mContext.getResources().getString(R.string.common_unpatrol));
            tv_status.setTextColor(mContext.getResources().getColor(R.color.un_bind_red));
        } else {
            tv_status.setText(mContext.getResources().getString(R.string.common_patrol));
            tv_status.setTextColor(mContext.getResources().getColor(R.color.bind_green));
        }

    }

    @Override
    public void onClick(View v) {
        if (listener!=null){
            listener.onItemClicked(v,getAdapterPosition());
        }
    }
  }
}
